package lab.dexter.bbsreader;

import lab.dexter.bbsreader.managers.ClassifiedListManager;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Portal extends ListActivity {
	
	private boolean isGuest;
	
	private String[] mListItems = {"去往讨论区", "首页导读", "收藏夹", "分类讨论区", "信箱"}; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);
		this.setListAdapter(adapter);
		String current_id = NewSMTHHttpClient.getClient().getLoggedInID();
		if(current_id.equalsIgnoreCase("guest")) {
			// disable 收藏夹 and 信箱
			isGuest = true;
		}
		else {
			isGuest = false;
		}
	}
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Intent intent;
		switch(position) {
		case 0:
			intent = new Intent(this, GotoBoard.class);
			startActivity(intent);
			break;
		case 1:
			intent = new Intent(this, ListBrowser.class);
			intent.setAction(Intent.ACTION_VIEW);
			intent.putExtra(ListBrowser.MGR, ListBrowser.MGR_SECTION_FOCUS);
			//intent.putExtra(ListBrowser.MGR, ListBrowser.MGR_SECTION_FOCUS);
			startActivity(intent);
			break;
		case 2:
			if(isGuest) {
				Toast.makeText(this.getApplicationContext(), "N/A for Guests", Toast.LENGTH_SHORT).show();
			}
			else {
				intent = new Intent(this, ListBrowser.class);
				intent.setAction(Intent.ACTION_VIEW);
				intent.putExtra(ListBrowser.MGR, ListBrowser.MGR_FAVORITE_LIST);
				intent.putExtra(ClassifiedListManager.PARAM_URL_PATH_PREFIX, "?act=fav");
				//intent.putExtra(ListBrowser.MGR, ListBrowser.MGR_SECTION_FOCUS);
				startActivity(intent);
			}
			break;
		case 3:
			intent = new Intent(this, ListBrowser.class);
			intent.setAction(Intent.ACTION_VIEW);
			intent.putExtra(ListBrowser.MGR, ListBrowser.MGR_CLASSFIED_LIST);
			intent.putExtra(ClassifiedListManager.PARAM_URL_PATH_PREFIX, "?act=list");
			//intent.putExtra(ListBrowser.MGR, ListBrowser.MGR_SECTION_FOCUS);
			startActivity(intent);
			break;
		case 4:
			if(isGuest) {
				Toast.makeText(this.getApplicationContext(), "N/A for Guests", Toast.LENGTH_SHORT).show();
			}
			else {
				Toast.makeText(this.getApplicationContext(), "Not implemented yet", Toast.LENGTH_SHORT).show();
			}
			break;
		default:
			Toast.makeText(this, "Unknow position: " + position, Toast.LENGTH_LONG).show();
		}
	}
}
